package com.itheima01;

import java.util.ArrayList;

public class StreamDemo {
    public static void main(String[] args) {
        ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add("斩杀是");
        arrayList.add("张恶女");
        arrayList.add("史蒂夫");
        arrayList.add("斩杀");
        arrayList.add("张夫");
        arrayList.add("张v吧");

        // 一般方法
        ArrayList<String> zhangArray = new ArrayList<String>();
        for (String s : arrayList) {
            if (s.startsWith("张")) {
                zhangArray.add(s);
            }
        }
        System.out.println(zhangArray);

        ArrayList<String> threeArray = new ArrayList<String>();
        for (String s : zhangArray) {
            if (s.length() == 3) {
                threeArray.add(s);
            }
        }
        System.out.println(threeArray);

        for (String s : threeArray) {
            System.out.println(s);
        }

        System.out.println("--------");

        // Stream 流改进
//        arrayList.stream().filter(s -> s.startsWith("张")).filter(s -> s.length() == 3).forEach(s -> System.out.println(s));
        arrayList.stream().filter(s -> s.startsWith("张")).filter(s -> s.length() == 3).forEach(System.out::println);

    }
}
